const mongoose = require('../fu/fu_db')


const FileSchema = new mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'loginyf'
    }, // 用户id
    aratar: String, // 头像
    text: String,  // 标题
    textarea: String, // 内容
    path: String, // 文件路径 图片
    address: String, // 地址
    like: {
        type: Number,
        default: 100,
    }, // 点赞数
    flag: {
        type: Boolean,
        default: false,
    }, // 是否点赞
})

const File = mongoose.model('File', FileSchema)


//内容评论
const CommentSchema = new mongoose.Schema({
    //评论者id
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'loginyf'
    }, // 用户
    //文章id
    article: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'File'
    },
    callId: {
        type: String,
        unique: true
    }, // 流水号
    content: String, // 评论内容
    time: {
        type: Date,
        default: Date.now
    }, // 评论时间,
    replies: [{
    }]

})

const Comment = mongoose.model('Comment', CommentSchema)


//二级评论
const ReplySchema = new mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'loginyf', // 回复者ID
    },
    self_callId: {
        type: String, // 自己的流水号
    },
    target_callId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Comment', // 引用的评论
    },
    content: {
        type: String, // 回复内容
    },
    time: {
        type: Date,
        default: Date.now, // 默认当前时间
    },
    replies: [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'three'
    }]
});
const Reply = mongoose.model('Reply', ReplySchema)

const threeSchema = new mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'loginyf', // 回复者ID
    },
    content: {
        type: String, // 回复内容
    },
    target_callId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Reply', // 引用的评论
    },
    time: {
        type: Date,
        default: Date.now, // 默认当前时间
    }
})

const three = mongoose.model('three', threeSchema)

module.exports = { File, Comment, Reply, three }
